package com.example.exp_2;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

public class Vote extends AppCompatActivity {
    Button but;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.vote);
        String arr[] = new String[]{"软件开发","软件测试","网络工程","计算机科学"};
        ArrayAdapter Adapter = new ArrayAdapter(this,R.layout.support_simple_spinner_dropdown_item,arr);
        Spinner spi = findViewById(R.id.spi);
        spi.setAdapter(Adapter);
        spi.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                but = findViewById(R.id.but);
                but.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        String a = spi.getSelectedItem().toString();
                        TextView text = findViewById(R.id.text);
                        text.setText(a);
                    }
                });

            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {

            }
        });
    }
}
